< previous page page_822 next page >

Page 822
Listing C.23 CREATEMETH.TXTUsing the Create Methods to Retrieve the Records Defined by a SELECT Statement
Dim OldDb As Database, NewQry As QueryDef, NewDyn As Recordset
Dim NewSnap As Recordset
'******************************************************
'Define the SELECT statement and store it to a variable
'******************************************************
SQLstate = "SELECT RI.[Item Description], SL.Quantity,"
SQLstate = SQLstate & " RI.Retail, _
     SL.Quantity * RI.Retail AS Subtot"
SQLstate = SQLstate & "FROM [Retail Items] AS RI, Sales AS SL"
SQLstate = SQLstate & "WHERE SL.[Item Code]=RI.[Item Code]"
'***********************
'Create dynaset directly
'***********************
Set NewDyn = OldDb.OpenRecordset(SQLstate, dbOpenDynaset)
'***************
'Create QueryDef
'***************
Set NewQry = OldDb.CreateQueryDef("Get Subtotals", SQLstate)
NewQry.Close
'*****************************
'Create snapshot from querydef
'*****************************
Set NewSnap = OldDb.OpenRecordset("Get Subtotals", dbOpenSnapshot)
You have seen how SELECT statements are used to create dynasets and snapshots. But, the comparison part of a WHERE clause and the sort list of an ORDER BY clause can also be used to set dynaset properties. The filter property of a dynaset is a WHERE statement without the WHERE keyword. When setting the filter property, you can use all the predicates described in the section "Using the WHERE Clause," earlier in this chapter. In a like manner, the sort property of a dynaset is an ORDER BY clause without the ORDER BY keywords.
Using SQL Statements with the Data Control
The data control uses the RecordSource property to create a recordset when the control is loaded. The RecordSource can be a table, a SELECT statement, or a predefined query. Therefore, the entire discussion on the SELECT statement (in the section "Using SELECT statements") applies to the creation of the recordset used with a data control.
note.gif When you specify a table name for the RecordSource property, Visual Basic uses the name to create a SELECT statement such as this:
SELECT * FROM table square.gif

 
< previous page page_822 next page >